package com.tiny.mirror.service.product.common.config;

import com.tiny.mirror.basic.cache.CacheProvider;
import com.tiny.mirror.basic.cache.CacheSettings;
import com.tiny.mirror.basic.cache.DefaultCacheConfig;
import com.tiny.mirror.basic.cache.registry.CacheRegistry;
import javax.annotation.Resource;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.springframework.cache.interceptor.CacheErrorHandler;
import org.springframework.cache.interceptor.CacheResolver;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CacheConfig extends DefaultCacheConfig {

  @Resource
  private RedissonClient redissonClient;

  @Override
  public CacheSettings cacheSettings() {
    CacheSettings settings = super.cacheSettings();
    settings.setCacheProvider(CacheProvider.REDISSON_MAP);
    return settings;
  }

  @Override
  protected void addCaches(CacheRegistry cacheRegistry) {
  }

  @Override
  protected Redisson getRedissonClient() {
    return (Redisson) redissonClient;
  }

  @Override
  public CacheResolver cacheResolver() {
    return null;
  }

  @Override
  public CacheErrorHandler errorHandler() {
    return null;
  }
}